<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>BeConsole</title>
    <link href="/style/flex.css" rel="stylesheet" type="text/css" media="all" />
    <link href="/style/app.css" rel="stylesheet" type="text/css" media="all" />
    <link rel="stylesheet" href="/lib/jquery-ui.css">
    <link rel="stylesheet" href="/lib/jquery.terminal/jquery.terminal-2.14.1.css">
    <link rel="stylesheet" href="/lib/jquery.terminal/emoji.css">
    <link rel="stylesheet" href="/lib/jquery.contextmenu/jquery.contextMenu.css">
  </head>
  <body dragover.prevent>
    <div id="app"></div>
    
    <script>
    window.runtime = {
      serial: false ,
      platform: 'html5' ,
    }
    if(navigator.userAgent.toLowerCase().indexOf(' electron/') > -1) {
      runtime.platform = "electron"
      runtime.serial = "node"
      
      window.nodeRequire = require; 
      delete window.require;
      delete window.exports; delete window.module; 
    }
    else if(typeof process !== "undefined" && process.versions && process.versions["node-webkit"]){
      runtime.platform = "nw.js"
      runtime.serial = "chrome"
    }

    let oriRegExp = RegExp
    window.RegExp = function(pattern, flags) {
        if(flags=='d') {
            flags = ''
        }
        return oriRegExp(pattern, flags)
  }
    </script> 
    <script src="/lib/jquery.js"></script>
    <script src="/lib/jquery-ui.js"></script>
    <!-- <script src=" lib/jquery-1.12.0.min.js"></script> -->
    <script>
    if(runtime.platform == 'electron') {
      window.require = window.nodeRequire
    }
    // 禁止浏览器默认的拖放文件行为
    $(document).on({
      dragleave:function(e){
          e.preventDefault();
      },
      drop:function(e){
          e.preventDefault();
      },
      dragenter:function(e){
          e.preventDefault();
      },
      dragover:function(e){
          e.preventDefault();
      }
    })
    </script>
    <script src="./lib/jquery.terminal/sprintf.min.js"></script>
    <script src="./lib/jquery.terminal/jquery.terminal-2.14.1.js"></script>
    <script src="./lib/jquery.contextmenu/jquery.contextMenu.js"></script>
    <script src="./lib/jquery.ui.touch-punch.js"></script>
    <script src="./lib/jquery-mousewheel.js"></script>


    <!-- <script src="./lib/raphael.js"></script>
    <script src="./lib/iro.js"></script> -->
    
    <!-- scratch -->
    <!-- <script src="lib/scratch3/scratch-blocks/blockly_uncompressed_vertical.js"></script>
    <script src="lib/scratch3/msg/messages.js"></script>
    <script src="lib/scratch3/msg/scratch_msgs.js"></script>
    <script src="lib/scratch3/blocks_compressed.js"></script>
    <script src="lib/scratch3/blocks_compressed_vertical.js"></script>
    <script src="lib/scratch3/scratch-vm.js"></script>
    <script src="lib/scratch3/hack/BlocklyFieldDropdownAsync.js"></script> -->
    <!-- <script>
    Blockly.Categories.beparts = "bepart"
    Blockly.Colours.bepart = {
      primary: Blockly.Colours.motion.primary ,
      secondary: Blockly.Colours.motion.secondary ,
      tertiary: Blockly.Colours.motion.tertiary
    }
    </script> -->

    <!-- three.js -->
    <!-- <script src="lib/three/three.js"></script>
    <script src="lib/three/GLTFLoader.js"></script>
		<script src="lib/three/OrbitControls.js"></script> -->
    
    <script type="module" src="./src/main.ts"></script>


    <script>
      let rec ;
  
  
      async function recStart() {
  
          let stream = await navigator.mediaDevices.getDisplayMedia({
              audio: true ,
              video: true ,
          })
          // refVideo.value.srcObject = stream
  
          let audioTracks = stream.getAudioTracks()
          if(!audioTracks.length) {
              return
          }
          console.log(audioTracks)
  
          if(rec){//清理掉已有的
              rec.close();
          };
          
          rec = Recorder({
              type:"pcm"
              ,sampleRate:16000
              ,bitRate:16
              ,sourceStream:stream //明确指定从这个流中录制音频
              ,onProcess:function(buffers,powerLevel,bufferDuration,bufferSampleRate){
                  // Runtime.Process.apply(null,arguments);
                  console.log(buffers)
              }
          })
          
          rec.open(function(){//打开这个流
                  rec.start()
              }
              ,function(msg){
                  console.error("无法打开音频流:"+msg)
              });
      }
  
      function recStop(){
          
          var rec2=rec;
          rec=0;
          if(!rec2){
              // Runtime.Log("未开始录音",1);
              return;
          };
          
          rec2.stop(function(blob,duration){
              rec2.close();//释放录音资源
              
              // Runtime.LogAudio(blob,duration,rec2);
          },function(msg){
              // Runtime.Log("录音失败:"+msg, 1);
          });
      }
      </script>


    <style>
      /* jquery.contextMenu 样式 */
      .context-menu-list {
          font-size: 14px;
          min-width: 8em;
      }
      .context-menu-item {
          padding: 0.2em 1em;
      }
      .n-button+.n-button {
        margin-left: 0px;
      }
      </style>
  </body>
</html>
